fix(room-io): ownership-aware FrameProcessor lifecycle management#1277
Draft
toubatbrian wants to merge 1 commit intomainfrom
Draft
fix(room-io): ownership-aware FrameProcessor lifecycle management#1277toubatbrian wants to merge 1 commit intomainfrom
toubatbrian wants to merge 1 commit intomainfrom
Conversation
Port of livekit/agents#5467. Adds a `processorOwned` flag and an internal `updateProcessor()` helper to `ParticipantAudioInputStream` so externally-provided `FrameProcessor` instances survive track transitions and are only closed on `close()`. JS only accepts an external processor (no selector callable), so the flag is always false for constructor-supplied processors; the structural pattern is retained for symmetry with Python and in case selector support is added later.
🦋 Changeset detectedLatest commit: 7d0adfa The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automated port of livekit/agents#5467 — fix(room-io): ownership-aware FrameProcessor lifecycle management — into
agents-js.What changed
In
agents/src/voice/room_io/_input.ts(ParticipantAudioInputStream):processorOwnedflag — tracks whether the currentframeProcessorwas created internally by the stream (owned) vs. supplied externally by the caller.updateProcessor(processor)helper — ownership-aware replacement:processor === undefinedand not owned → no-op (external processors survive transitions).close()it.processorOwnedflag.closeStream()now callsupdateProcessor(undefined)after clearing the input stream and publication. For externally-provided processors this is a safe no-op; if/when selector support is ever added, it will correctly dispose of selector-owned processors.close()still closes the processor unconditionally (matches Python'saclose()semantics), which handles the externally-provided case._input.test.tscovering the four ownership invariants (noop on external, closes-and-clears on owned, replacement semantics, self-replacement noop).@livekit/agentspatch.Each change carries a
// Ref: python livekit-agents/livekit/agents/voice/room_io/_input.py - <lines>pointer as required byCLAUDE.md.Implementation nuances (language-level differences from Python)
The Python PR introduces ownership tracking primarily to fix a bug specific to the selector callable noise-cancellation pattern, where
_ParticipantAudioInputStreamcan be constructed with a callable that is invoked per-track to produce a freshFrameProcessor. Those selector-produced processors are owned by the stream and must be closed on track switch / stream close — while externally-provided processors must survive track switches.agents-js today does not support the selector callable pattern. Its
noiseCancellationoption is typed asNoiseCancellationOptions | FrameProcessor<AudioFrame>— always an external processor when aFrameProcessoris passed. Because of that:closeStream()never closed the processor; onlyclose()did. No externally-provided processor was being prematurely disposed.processorOwnedflag is alwaysfalsefor processors provided via the constructor. The helper is structured so that if selector support is added later, only_create_stream-equivalent call sites need to callupdateProcessor(newProcessor)with the new processor and the flag will flip on.Not ported: selector callable support itself (
NoiseCancellationSelector,NoiseCancellationParams). Those are larger API additions that precede the Python PR and are out of scope for this port.File-by-file reference map
livekit/agents@ #5467)livekit-agents/livekit/agents/voice/room_io/_input.py(55-56)agents/src/voice/room_io/_input.ts(27-33)_processor_owned→processorOwnedlivekit-agents/livekit/agents/voice/room_io/_input.py(172-181)agents/src/voice/room_io/_input.ts(65-79)_update_processor→updateProcessorlivekit-agents/livekit/agents/voice/room_io/_input.py(188)agents/src/voice/room_io/_input.ts(149-159)_close_streamuses_update_processor(None)livekit-agents/livekit/agents/voice/room_io/_input.py(aclose)agents/src/voice/room_io/_input.ts(212-226)tests/test_room_io.py(selector tests)tests/test_room_io.py(direct processor lifecycle portions)agents/src/voice/room_io/_input.test.tsupdateProcessorinvariantsTest plan
pnpm build:agents— succeeds.pnpm format:check— clean.pnpm exec eslinton changed files — clean.pnpm exec vitest run src/voice/room_io/_input.test.ts— 4/4 tests pass.FrameProcessor(e.g. AI-coustics plugin) against a LiveKit room, confirm it survives track republishes and is closed on agent shutdown.NoiseCancellationOptions-only configurations.Reviewers
cc @toubatbrian @livekit/agent-devs — please review the ported pattern and decide whether to hold this until selector-callable support is added to JS, or land it as a structural no-op now.